package cn.tedu.csmall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;

/**
 * Validation配置类
 * @author 何惠民
 */
@Slf4j
@Configuration
public class ValidationConfiguration {
    public ValidationConfiguration() {
        log.debug("创建配置类对象:ValidationConfiguration");
    }
    @Bean
    public javax.validation.Validator validation(){
        return Validation.byProvider(HibernateValidator.class)
                .configure() //开始配置
                .failFast(true)//快速失败,即检查请求参数时,一旦发现某个参数不符合规则,则失败,并停止检查(剩余参数不检查)
                .buildValidatorFactory()
                .getValidator();
    }
}
